﻿#include "PyFITKPhyscisPropRibbed.h"
#include "FITKAcousticsPhysics.h"
#include "FITKAcousticsAbsPhysicsProp.h"
#include "FITKPhyscisPropertyRibbed.h"
#include "FITKPhyscisPropertyRibInfo.h"
namespace Acoustics {
    PyFITKPhyscisPropRibbed::PyFITKPhyscisPropRibbed(const QString & name) :
        Acoustics::PyFITKPhyscisPropBase(name)
    {
    }

    bool PyFITKPhyscisPropRibbed::setRibs_1(const QString & beam, double spacing, double dev, double offset, double orientation)
    {
        if (!_phyProp || beam == "" || spacing < 0|| orientation < 0)return false;

        Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
        if (phy == nullptr) return false;
        Acoustics::FITKAcousticsPhysicsPropManager* propMgr = phy->getPhysicsPropManager();
        if (propMgr == nullptr) return false;
        if (!propMgr->getDataByName(beam))return false;

        FITKPhyscisPropertyRibbed *ribbed = dynamic_cast<Acoustics::FITKPhyscisPropertyRibbed*>(_phyProp);
        if (!ribbed)return false;
        FITKPhyscisPropertyRibInfo* r = ribbed->getDri1RibInfo();
        if(!r)return false;
        int beamlID = propMgr->getDataByName(beam)->getDataObjectID();

        r->setBeamPropID(beamlID);
        r->setSpacing(spacing);
        r->setSpacingDevFraction(dev);
        r->setOffset(offset);
        if (orientation < 90 || qFuzzyCompare(orientation,360))  orientation = 0;
        else if (orientation < 180)  orientation = 90;
        else if (orientation < 270)  orientation = 180;
        else if (orientation < 360)  orientation = 270;
        r->setOrientation(orientation);

        return true;
    }

    bool PyFITKPhyscisPropRibbed::setRibs_2(const QString & beam, double spacing, double dev, double offset, double orientation)
    {
        if (!_phyProp || beam == "" || spacing < 0 || orientation < 0)return false;

        Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
        if (phy == nullptr) return false;
        Acoustics::FITKAcousticsPhysicsPropManager* propMgr = phy->getPhysicsPropManager();
        if (propMgr == nullptr) return false;
        if (!propMgr->getDataByName(beam))return false;

        FITKPhyscisPropertyRibbed *ribbed = dynamic_cast<Acoustics::FITKPhyscisPropertyRibbed*>(_phyProp);
        if (!ribbed)return false;
        FITKPhyscisPropertyRibInfo* r = ribbed->getDri2RibInfo();
        if (!r)return false;
    //类型判断？
        int beamlID = propMgr->getDataByName(beam)->getDataObjectID();

        r->setBeamPropID(beamlID);
        r->setSpacing(spacing);
        r->setSpacingDevFraction(dev);
        r->setOffset(offset);
        if (orientation < 90 || qFuzzyCompare(orientation, 360))  orientation = 0;
        else if (orientation < 180)  orientation = 90;
        else if (orientation < 270)  orientation = 180;
        else if (orientation < 360)  orientation = 270;
        r->setOrientation(orientation);

        return true;
    }

    bool PyFITKPhyscisPropRibbed::disableRibs_2()
    {
        if(!_phyProp)return false;
        FITKPhyscisPropertyRibbed *ribbed = dynamic_cast<Acoustics::FITKPhyscisPropertyRibbed*>(_phyProp);
        if (!ribbed)return false;

        ribbed->getDri2RibInfo()->setBeamPropID(-1);
        return true;
    }

    bool PyFITKPhyscisPropRibbed::setBaseAngle(double angle)
    {
        if (!_phyProp)return false;
        FITKPhyscisPropertyRibbed *ribbed = dynamic_cast<Acoustics::FITKPhyscisPropertyRibbed*>(_phyProp);
        if (!ribbed)return false;

        ribbed->setBaseAngle(angle);
        return true;
    }

    bool PyFITKPhyscisPropRibbed::setSkinSection(const QString & skinName)
    {
        if (!_phyProp|| skinName=="")return false;
        FITKPhyscisPropertyRibbed *ribbed = dynamic_cast<Acoustics::FITKPhyscisPropertyRibbed*>(_phyProp);
        if (!ribbed)return false;
        Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
        if (phy == nullptr) return false;
        Acoustics::FITKAcousticsPhysicsPropManager* propMgr = phy->getPhysicsPropManager();
        if (propMgr == nullptr) return false;
        if (!propMgr->getDataByName(skinName))return false;
    //类型判断？
        int shellID = propMgr->getDataByName(skinName)->getDataObjectID();
        ribbed->setSkinPropID(shellID);
        return true;
    }

    bool PyFITKPhyscisPropRibbed::createPhyscisProp(const QString & name)
    {
        if (name == "")return false;
        Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
        if (phy == nullptr) return false;
        Acoustics::FITKAcousticsPhysicsPropManager* propMgr = phy->getPhysicsPropManager();
        if (propMgr == nullptr) return false;
        if (propMgr->getDataByName(name))return false;

        FITKPhyscisPropertyRibbed * ribbed = new FITKPhyscisPropertyRibbed();
        ribbed->setDataObjectName(name);
        _phyProp = ribbed;
        propMgr->appendDataObj(_phyProp);
        return true;
    }
}